package com.zbkj.crmebadmin.controller;

import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Component;

import java.util.Random;
import java.util.concurrent.Future;

@Component
public class Task1 {
    public static Random random = new Random();
    @Async
    public Future<String> doTaskOne() throws InterruptedException {
        System.out.println("start 任务1...");
        long start = System.currentTimeMillis();
        Thread.sleep(random.nextInt(100));
        long end = System.currentTimeMillis();
        System.out.println("end 任务1...耗时：" + (end - start) + "毫秒");
        return new AsyncResult<String> ("hello world");
    }
    @Async
    public void doTaskTwo() throws InterruptedException {
        System.out.println("start 任务2...");
        long start = System.currentTimeMillis();
        Thread.sleep(random.nextInt(100));
        long end = System.currentTimeMillis();
        System.out.println("end 任务2...耗时：" + (end - start) + "毫秒");
    }
    @Async
    public void doTaskThree() throws InterruptedException {
        System.out.println("start 任务3...");
        long start = System.currentTimeMillis();
        Thread.sleep(random.nextInt(100));
        long end = System.currentTimeMillis();
        System.out.println("end 任务3...耗时：" + (end - start) + "毫秒");
    }
}
